package com.deep.transaction.demo.controller;


import com.deep.transaction.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 *
 */
@RestController
public class StudentController {

    @Autowired
    @Qualifier("demoStudentService")
    private StudentService studentService;

    @GetMapping(value = "/test/{type}")
    public String testTransaction(@PathVariable("type") int type) {
        switch (type) {
            case 1:
                studentService.testPropagationRequired();
                break;
            case 2:
                studentService.testPropagationRequiresNew();
                break;
            case 3:
                studentService.testPropagationMandatory();
                break;
            case 4:
                studentService.testPropagationSupports();
                break;
            case 5:
                studentService.testPropagationNested();
                break;
            case 6:
                studentService.testPropagationNever();
                break;
            case 7:
                studentService.testPropagationNotSupported();
                break;
            case 8:
                studentService.testPrivateMethod();
                break;
            case 9:
                studentService.testInnerMethod();
                break;
            case 10:
                try {
                    studentService.testExceptionNotMatch();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case 11:
                studentService.testExceptionCatched();
                break;
            default:
                studentService.testOk();
                break;
        }
        return "ok";
    }
}
